import { getVarStyle } from "./tooler";

export interface IToken {
    chainId: number;
    address: string;
    name: string;
    symbol: string;
    decimals: number;
    logoURI: string;
}
export class Core {
    public static red = getVarStyle("--lose");
    public static green = getVarStyle("--win");

    private static _ins: Core;
    // 私有构造函数
    constructor(inner: Inner) {
        if (!inner) {
            throw new Error("Cannot instantiate Core without param");
        }
        if (inner instanceof Inner == false) {
            throw new Error("Cannot instantiate Core without inner");
        }
    }

    // 静态方法，用于获取类的实例
    static get ins() {
        if (!Core._ins) {
            Core._ins = new Core(new Inner());
            console.log("instantiate Core");
        }
        return Core._ins;
    }

    checkThirdCallbak() {
        let isCallback = false;
        // http://alpha.chainingview.io/oauth/twitter?oauth_token=sIBgPAAAAAABqrFtAAABjIx2wFA&oauth_verifier=rF6iVA2Gj1Ks4jBJJik7JZKeFKGidcfj
        // http://chainingview.natapp1.cc/?state=3EAB37D9D5310BFE&access_token=ya29.a0AfB_byCbG1H0APQNqQU-ImMyJD0O2auuy3Iz0vWn4yv20ag9RdlPE7TavJ7YY1-1ueh1U57CDyIvDNKaHpJxDYvE2LlYJoSa4rC1zhRzFbr2zBAtPVIPNIeqe2HyTR8BX4-uJLwt72yUOVA_PxSH7jTCTJ2hY-FqJ78gaCgYKAeQSARISFQGOcNnCirNZF0taFpRznBbCTxCBUw0171#/layout/home
        if (location.href.indexOf("access_token") != -1) {
            //google回调url
            isCallback = true;
        } else if (location.href.indexOf("/oauth/twitter") != -1) {
            //twitter回调url
            isCallback = true;
        }

        if (isCallback) {
            if (window.opener) {
                localStorage.setItem("other", location.href);
                window.opener.postMessage(location.href);
                setTimeout(() => {
                    window.close();
                }, 1000);
            }
        } else {
        }
        return isCallback;
    }

    hideLoading() {
        setTimeout(() => {
            let dom: any = document.querySelector(".lds-roller-box");
            dom.style.display = "none";
        }, 200);
    }

    addListener() {}
}

class Inner {}
